#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>


void Swap(int* x, int* y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}






void SelectSort(int* a, int n)
{
	int begin = 0, end = n - 1;

	while (begin < end)
	{
		int mini = begin, maxi = begin;
		for (int i = begin + 1; i <= end; ++i)
		{
			if (a[i] > a[maxi]) {
				maxi = i;
			}
			if (a[i] < a[mini])
			{
				mini = i;
			}
		}
		Swap(&a[begin], &a[mini]);
		if (begin == maxi)
			maxi = mini;

		Swap(&a[end], &a[maxi]);

		++begin;
		--end;
	}
	
}


void PrintArray(int* a, int n)
{
	for (int i = 0; i < n ; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}

int main()
{
	//int a[] = { 5,4,6,3,8,1,9,7,2 };
	int a[] = { 9,1,2,5,7,4,6,3 };
	int sz = sizeof(a) / sizeof(a[0]);
	PrintArray(a, sz);
	SelectSort(a, sz);
	PrintArray(a, sz);
	return 0;
}











int main1()
{
	int a = 10;
	int b = 20;
	Swap(&a, &b);
	printf("%d  %d ", a, b);
	return 0;
}













